import { CrownOutlined } from '@ant-design/icons';
import { MenuDataItem } from '@ant-design/pro-layout';
import PERM_ENUM from '@/permission/PermEnum'

// 菜单列表
export const menus = [
  {
    path: '/',
    name: '主页',
  },
  {
    path: '/banks',
    name: '题库',
  },
  {
    path: '/questions',
    name: '题目',
  },
  {
    path: '/admin',
    name: '管理',
    icon: <CrownOutlined />,
    needPerm: PERM_ENUM.ADMIN,
    children: [
      {
        path: '/admin/user',
        name: '用户管理',
        needPerm: PERM_ENUM.ADMIN,
      },
      {
        path: '/admin/bank',
        name: '题库管理',
        needPerm: PERM_ENUM.ADMIN,
      },
      {
        path: '/admin/question',
        name: '题目管理',
        needPerm: PERM_ENUM.ADMIN,
      },
    ],
  },
] as MenuDataItem[];

export const findAllMenuByPath = (path: string): MenuDataItem | null => {
  return findMenuByPath(menus, path)
};

export const findMenuByPath = (
  menus: MenuDataItem[],
  path: string,
): MenuDataItem | null => {
  for (const menu of menus) {
    if (menu.path === path) {
      return menu;
    }
    if (menu.children) {
      const matchMenuItem = findMenuByPath(menu.children, path);
      if (matchMenuItem) {
        return matchMenuItem;
      }
    }
  }
  return null;
};
